<!DOCTYPE html>
<html lang="en">
    <head>
        <title></title>
        <meta charset="UTF-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
    </head>
    <body>
    
    </body>
    <script src="./node_modules/jquery/dist/jquery.min.js"></script>
    <script>

        var dtd = $.Deferred(); //新建一个deferred对象
        var wait  = function (dtd){
            var task = function(){
                alert('task成功')
                dtd.resolve(); //改变deferred对象的执行状态
            }
            setTimeout(task, 5000);
            return dtd
        }
        $.when(wait(dtd))
        .done(function(){ alert('成功') })
        .fail(function(){ alert('失败') })
    </script>
</html>